home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2006 May
/
PCWMAY06.iso
/
Software
/
Resources
/
HTMLGate 12.2.1B
/
htmlgate.exe
/
{app}
/
Cookies
/
cookie4.txt
< prev
next >
Wrap
Text File
|
2002-09-26
|
2KB
|
37 lines
<SCRIPT LANGUAGE="JavaScript">
<!--
var cookieObject = document.cookie;
function getCookie(name) {
name += "="; // append '=' to name string
var i = 0; // index of first name=value pair
while (i < cookieObject.length) {
var offset = i + name.length; // end of section to compare with name string
if (cookieObject.substring(i, offset) == name) { // if string matches
var endstr = cookieObject.indexOf(";", offset); // locate end of name=value pair
if (endstr == -1) endstr = cookieObject.length;
return unescape(cookieObject.substring(offset, endstr)); // return cookie value section
}
i = cookieObject.indexOf(" ", i) + 1; // move i to next name=value pair
if (i == 0) break; // no more values in cookie string
}
return null; // cookie not found
}
var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000);
var headCount = getCookie("headCount") || 1;
var userName = getCookie("userName") || prompt("Please Enter Your Name:", "Anonymous");
if (userName == null || userName == "")
userName = "Anonymous";
if (headCount == 1) alert("Welcome, " + userName + ", this is your first visit");
else if (headCount == 2) alert("Hi, " + userName + ", this is your second visit");
else alert("Welcome back " + userName + "\r\nYou have been here " + headCount + " times.");
document.cookie = "headCount=" + (++headCount) + "; expires=" + expiry.toGMTString();
document.cookie = "userName=" + escape(userName) + "; expires=" + expiry.toGMTString();
-->
</SCRIPT>